public class test {
    /**
     * Definition for a binary tree node.
     * public class TreeNode {
     *     int val;
     *     TreeNode left;
     *     TreeNode right;
     *     TreeNode() {}
     *     TreeNode(int val) { this.val = val; }
     *     TreeNode(int val, TreeNode left, TreeNode right) {
     *         this.val = val;
     *         this.left = left;
     *         this.right = right;
     *     }
     * }
     */
    class FindElements {
        private final Set<Integer> s = new HashSet<>();

        public FindElements(TreeNode root) {
            dfs(root,0);
        }

        public boolean find(int target) {
            return s.contains(target);
        }
        private void dfs(TreeNode head,int val){
            if(head == null){
                return;
            }
            s.add(val);//加入到哈希表当中
            dfs(head.left,2 * val + 1);
            dfs(head.right,2 * val + 2);
        }
    }

/**
 * Your FindElements object will be instantiated and called as such:
 * FindElements obj = new FindElements(root);
 * boolean param_1 = obj.find(target);
 */
}
